package com.youbug.system.schedule;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;

import java.util.Map;

@Slf4j
public abstract class AbstractJobExecutor {

    public void doExec(AbstractJob job, boolean auto){
        boolean isError = false;
        try{
            if(ObjectUtils.isEmpty(job)){
                log.error("任务不存在");
                return;
            }
            if (!job.start(auto)){return;}
            job.exec();
        }catch (Exception e){
            isError = true;
            log.error(job.getExecuting() + "执行异常", e);
        }finally {
            job.end(isError);
        }
    }
}
